package com.rz.htk.print.controller;

import com.rz.core.kit.RespKit;
import com.rz.core.resp.ResultResp;
import com.rz.htk.print.entity.PrintTempField;
import com.rz.htk.print.entity.PrintTemplate;
import com.rz.htk.print.service.IPrintTempFieldService;
import com.rz.htk.print.service.IPrintTemplateService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("printTemp")
public class PrintTemplateCtrl {
    @Resource private IPrintTemplateService printTemplateService;
    @Resource private IPrintTempFieldService printTempFieldService;

    @PostMapping("getList")
    public ResultResp getList(){
        return RespKit.success(printTemplateService.list());
    }

    @PostMapping("getFields/{printTempId}")
    public ResultResp getFields(@PathVariable Integer printTempId){
        return RespKit.success(printTempFieldService.getFields(printTempId));
    }

    @PostMapping("delField/{fieldId}")
    public ResultResp delField(@PathVariable Integer fieldId){
        return RespKit.success(printTempFieldService.removeById(fieldId));
    }

    @PostMapping("save")
    public ResultResp save(@RequestBody PrintTemplate printTemplate){
        return RespKit.success(printTemplateService.saveOrUpdate(printTemplate));
    }

    @PostMapping("saveField")
    public ResultResp saveField(@RequestBody PrintTempField printTempField){
        printTempFieldService.saveOrUpdate(printTempField);
        return RespKit.success(printTempField);
    }

    @PostMapping("saveFields")
    public ResultResp saveFields(@RequestBody List<PrintTempField> printTempFields){
        return RespKit.success(printTempFieldService.saveOrUpdateBatch(printTempFields));
    }

}
